Strict

Import agfx

Global myTmpScreen:TTmpScreen

Class TAgfx_test_app Extends TFramework

	Method OnCreate:Int()
		
		'DEVICE.SetFps(30)		' default FPS is 60
		
		Super.OnCreate()
				
		myTmpScreen = New TTmpScreen		
		myTmpScreen.Prepare()
		
		Return 0
	End

End

Const TWEEN_X% = 10
Const TWEEN_Y% = 10
Const TWEEN_WIDTH% = 200
Const TWEEN_HEIGHT% = 30
Const TWEEN_GAP% = 30

Class TTmpScreen Extends TScreen
	
	Field tween:TTween
	
	Method Start:Void()
		TTween.CacheTweens()
		Self.tween = New TTween()
		Self.tween = TTween.CreateLinear(200, TWEEN_X, TWEEN_X+TWEEN_WIDTH, 0)
		
	End
	
	' main app logic loop update
	Method Update:Void()
		TTween.UpdateAll(2.0*AppSpeed())
		If KeyHit(KEY_1) Then 
			Self.tween = TTween.CreateLinear(100, TWEEN_X, TWEEN_X+TWEEN_WIDTH, TWEEN_X)
		EndIf
		
		If KeyHit(KEY_2) Then 
			Self.tween = TTween.CreateBounce(100, TWEEN_X+TWEEN_WIDTH, TWEEN_X, TWEEN_X+TWEEN_WIDTH)
		EndIf
		
		If KeyHit(KEY_3) Then 
			Self.tween = TTween.CreateSine(100,TWEEN_X+(TWEEN_WIDTH/2),0,TWEEN_WIDTH/2)
		EndIf
		
		If KeyHit(KEY_4) Then 
			Self.tween = TTween.CreateLinear(200,TWEEN_X,TWEEN_X+TWEEN_WIDTH,TWEEN_X)
			Self.tween.AddChain(TTween.CreateBounce(100,TWEEN_X+TWEEN_WIDTH,TWEEN_X,TWEEN_X+TWEEN_WIDTH))
			Self.tween.AddChain(TTween.CreateSine(400,TWEEN_X+(TWEEN_WIDTH/2),0.25,TWEEN_WIDTH/2,2.0/3.0))
		EndIf
		
	
	End
	
	' main app render loop
	Method Render:Void()
		Cls
		Local y:Int = TWEEN_Y

		DrawLine(Self.tween.value, y, Self.tween.value, y+TWEEN_HEIGHT)
		PrintTweenState(Self.tween, TWEEN_X + TWEEN_WIDTH + 10, y)

		DrawText("[1] - linear tween.",10,60)
		DrawText("[2] - Bounce tween.",10,80)
		DrawText("[3] - Sine tween.",10,100)
		DrawText("[4] - Combined via chain [linear -> bounce -> sine] tween.",10,120)
		
	End
	
	Method PrintTweenState:Void(twn:TTween, x%, y%)
		Local t:TTween = twn
		If twn.chainFirst >= 0 Then twn = TTween.tweens[twn.chainActive]
		Select twn.type
			Case TTween.TWEEN_TYPE_LINEAR
				DrawText("Linear: len="+twn.length+", start="+twn.linearStart+", end="+twn.linearEnd+", initial="+twn.linearInitial, x, y)

			Case TTween.TWEEN_TYPE_BOUNCE
				DrawText("Bounce: len="+twn.length+", start="+twn.bounceStart+", end="+twn.bounceEnd+", initial="+twn.bounceInitial, x, y)

			Case TTween.TWEEN_TYPE_SINE
				DrawText("Sine: len="+twn.length+", off="+twn.waveOffset+", phase="+twn.wavePhase+", amp="+twn.waveAmplitude+", wavelen="+twn.waveLength, x, y)
		End
		If twn.chainFirst < 0 Then
			DrawText("Value: "+Int(t.value), x, y+15)
		Else
			DrawText("Value: "+Int(t.value)+", first="+twn.chainFirst+", prev="+twn.chainPrevious+", next="+twn.chainNext+", last="+twn.chainLast+", active="+twn.chainActive, x, y+15)
		End
	End

	
End

